var local="http://47.104.10.151";
var xmlHttp;
var stock_id12;
var stock_id11;
var stock_id10;
var stock_id9;
var stock_id8;
var stock_id7;
var stock_id6;
var stock_id5;
var stock_id4;
var stock_id3;
var stock_id2;
var stock_id1;
var thisURL=decodeURI(document.URL);
var stockName=thisURL.split('?')[1];
function creatxmlHTTP() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlHttp=new XMLHttpRequest();
    }else {
        // IE6, IE5 浏览器执行代码
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttp;
}

var totalPages;
var page=0;

function seachStock() {
    xmlHttp=creatxmlHTTP();
    var url=local+":8080/search/searchStock";

    //拼接字符
    txt="model="+stockName+"&page="+page;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);

    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");
            var input1 = document.getElementsByName("Bid1");
            if (json.data.content[0].tax_status == 0) {
                input1[8].value = "无税率";
            } else if(json.data.content[0].tax_status == 1){
                input1[8].value = "17%";
            }
            stock_id1=json.data.content[0].keyId;
            input1[0].value = 1;
            input1[1].value = json.data.content[0].product_name;
            input1[2].value = json.data.content[0].model_code ;
            input1[3].value = json.data.content[0].size;
            input1[4].value = json.data.content[0].brand;
            input1[5].value = json.data.content[0].sale_price;
            input1[6].value = json.data.content[0].inventory;
            input1[7].value = json.data.content[0].area_name;

            totalPages=json.data.totalPages;

            var input2 = document.getElementsByName("Bid2");
            if (json.data.content[0].tax_status == 0) {
                input2[8].value = "无税率";
            } else if(json.data.content[0].tax_status == 1){
                input2[8].value = "17%";
            }
            stock_id2=json.data.content[1].keyId;
            input2[0].value = 2;
            input2[1].value = json.data.content[1].product_name;
            input2[2].value = json.data.content[1].model_code ;
            input2[3].value = json.data.content[1].size;
            input2[4].value = json.data.content[1].brand;
            input2[5].value = json.data.content[1].sale_price;
            input2[6].value = json.data.content[1].inventory;
            input2[7].value = json.data.content[1].area_name;

            var input3 = document.getElementsByName("Bid3");
            if (json.data.content[0].tax_status == 0) {
                input3[8].value = "无税率";
            } else if(json.data.content[0].tax_status == 1){
                input3[8].value = "17%";
            }
            stock_id3=json.data.content[2].keyId;
            input3[0].value = 3;
            input3[1].value = json.data.content[2].product_name;
            input3[2].value = json.data.content[2].model_code ;
            input3[3].value = json.data.content[2].size;
            input3[4].value = json.data.content[2].brand;
            input3[5].value = json.data.content[2].sale_price;
            input3[6].value = json.data.content[2].inventory;
            input3[7].value = json.data.content[2].area_name;
        }

        var input4 = document.getElementsByName("Bid4");
        if (json.data.content[0].tax_status == 0) {
            input4[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input4[8].value = "17%";
        }
        stock_id4=json.data.content[3].keyId;
        input4[0].value = 4;
        input4[1].value = json.data.content[3].product_name;
        input4[2].value = json.data.content[3].model_code ;
        input4[3].value = json.data.content[3].size;
        input4[4].value = json.data.content[3].brand;
        input4[5].value = json.data.content[3].sale_price;
        input4[6].value = json.data.content[3].inventory;
        input4[7].value = json.data.content[3].area_name;

        var input5 = document.getElementsByName("Bid5");
        if (json.data.content[0].tax_status == 0) {
            input5[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input5[8].value = "17%";
        }
        stock_id5=json.data.content[4].keyId;
        input5[0].value = 5;
        input5[1].value = json.data.content[4].product_name;
        input5[2].value = json.data.content[4].model_code ;
        input5[3].value = json.data.content[4].size;
        input5[4].value = json.data.content[4].brand;
        input5[5].value = json.data.content[4].sale_price;
        input5[6].value = json.data.content[4].inventory;
        input5[7].value = json.data.content[4].area_name;

        var input6 = document.getElementsByName("Bid6");
        if (json.data.content[0].tax_status == 0) {
            input6[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input6[8].value = "17%";
        }
        stock_id6=json.data.content[5].keyId;
        input6[0].value = 6;
        input6[1].value = json.data.content[5].product_name;
        input6[2].value = json.data.content[5].model_code ;
        input6[3].value = json.data.content[5].size;
        input6[4].value = json.data.content[5].brand;
        input6[5].value = json.data.content[5].sale_price;
        input6[6].value = json.data.content[5].inventory;
        input6[7].value = json.data.content[5].area_name;

        var input7 = document.getElementsByName("Bid7");
        if (json.data.content[0].tax_status == 0) {
            input7[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input7[8].value = "17%";
        }
        stock_id7=json.data.content[6].keyId;
        input7[0].value = 7;
        input7[1].value = json.data.content[6].product_name;
        input7[2].value = json.data.content[6].model_code ;
        input7[3].value = json.data.content[6].size;
        input7[4].value = json.data.content[6].brand;
        input7[5].value = json.data.content[6].sale_price;
        input7[6].value = json.data.content[6].inventory;
        input7[7].value = json.data.content[6].area_name;

        var input8 = document.getElementsByName("Bid8");
        if (json.data.content[0].tax_status == 0) {
            input8[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input8[8].value = "17%";
        }
        stock_id8=json.data.content[7].keyId;
        input8[0].value =8;
        input8[1].value = json.data.content[7].product_name;
        input8[2].value = json.data.content[7].model_code ;
        input8[3].value = json.data.content[7].size;
        input8[4].value = json.data.content[7].brand;
        input8[5].value = json.data.content[7].sale_price;
        input8[6].value = json.data.content[7].inventory;
        input8[7].value = json.data.content[7].area_name;

        var input9 = document.getElementsByName("Bid9");
        if (json.data.content[0].tax_status == 0) {
            input9[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input9[8].value = "17%";
        }
        stock_id9=json.data.content[8].keyId;
        input9[0].value = 9;
        input9[1].value = json.data.content[8].product_name;
        input9[2].value = json.data.content[8].model_code ;
        input9[3].value = json.data.content[8].size;
        input9[4].value = json.data.content[8].brand;
        input9[5].value = json.data.content[8].sale_price;
        input9[6].value = json.data.content[8].inventory;
        input9[7].value = json.data.content[8].area_name;

        var input10 = document.getElementsByName("Bid10");
        if (json.data.content[0].tax_status == 0) {
            input10[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input10[8].value = "17%";
        }
        stock_id10=json.data.content[9].keyId;
        input10[0].value = 10;
        input10[1].value = json.data.content[9].product_name;
        input10[2].value = json.data.content[9].model_code ;
        input10[3].value = json.data.content[9].size;
        input10[4].value = json.data.content[9].brand;
        input10[5].value = json.data.content[9].sale_price;
        input10[6].value = json.data.content[9].inventory;
        input10[7].value = json.data.content[9].area_name;

        var input11 = document.getElementsByName("Bid11");
        if (json.data.content[0].tax_status == 0) {
            input11[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input11[8].value = "17%";
        }
        stock_id11=json.data.content[10].keyId;
        input11[0].value = 11;
        input11[1].value = json.data.content[10].product_name;
        input11[2].value = json.data.content[10].model_code ;
        input11[3].value = json.data.content[10].size;
        input11[4].value = json.data.content[10].brand;
        input11[5].value = json.data.content[10].sale_price;
        input11[6].value = json.data.content[10].inventory;
        input11[7].value = json.data.content[10].area_name;

        var input12 = document.getElementsByName("Bid12");
        if (json.data.content[0].tax_status == 0) {
            input12[8].value = "无税率";
        } else if(json.data.content[0].tax_status == 1){
            input12[8].value = "17%";
        }
        stock_id12=json.data.content[11].keyId;
        input12[0].value = 12;
        input12[1].value = json.data.content[11].product_name;
        input12[2].value = json.data.content[11].model_code ;
        input12[3].value = json.data.content[11].size;
        input12[4].value = json.data.content[11].brand;
        input12[5].value = json.data.content[11].sale_price;
        input12[6].value = json.data.content[11].inventory;
        input12[7].value = json.data.content[11].area_name;
    }

}



function addPage() {

    if(totalPages>page+1){
        for(var i=0;i<document.getElementsByName("Bid1").length;i++){
            document.getElementsByName("Bid1")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid2").length;i++){
            document.getElementsByName("Bid2")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid3").length;i++){
            document.getElementsByName("Bid3")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid4").length;i++){
            document.getElementsByName("Bid4")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid5").length;i++){
            document.getElementsByName("Bid5")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid6").length;i++){
            document.getElementsByName("Bid6")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid7").length;i++){
            document.getElementsByName("Bid7")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid8").length;i++){
            document.getElementsByName("Bid8")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid9").length;i++){
            document.getElementsByName("Bid9")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid10").length;i++){
            document.getElementsByName("Bid10")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid11").length;i++){
            document.getElementsByName("Bid11")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid12").length;i++){
            document.getElementsByName("Bid12")[i].value="";
        }

        page++;
        seachStock();
    }
    else alert("已经是最后一页");

}
function decPage() {
    if(page-1>=0){
        for(var i=0;i<document.getElementsByName("Bid1").length;i++){
            document.getElementsByName("Bid1")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid2").length;i++){
            document.getElementsByName("Bid2")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid3").length;i++){
            document.getElementsByName("Bid3")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid4").length;i++){
            document.getElementsByName("Bid4")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid5").length;i++){
            document.getElementsByName("Bid5")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid6").length;i++){
            document.getElementsByName("Bid6")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid7").length;i++){
            document.getElementsByName("Bid7")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid8").length;i++){
            document.getElementsByName("Bid8")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid9").length;i++){
            document.getElementsByName("Bid9")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid10").length;i++){
            document.getElementsByName("Bid10")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid11").length;i++){
            document.getElementsByName("Bid11")[i].value="";
        }
        for(var i=0;i<document.getElementsByName("Bid12").length;i++){
            document.getElementsByName("Bid12")[i].value="";
        }
        page--;
        seachStock();
    }
    else alert("第一页");
}